<template><div><h2 id="查询过滤" tabindex="-1"><a class="header-anchor" href="#查询过滤"><span>查询过滤</span></a></h2>
<p><code v-pre>model-grid</code>提供了一系列的方法实现表格数据的查询过滤：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token comment">// 禁用</span></span>
<span class="line"><span class="token variable">$grid</span><span class="token operator">-></span><span class="token function">disableFilter</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token comment">// 显示</span></span>
<span class="line"><span class="token variable">$grid</span><span class="token operator">-></span><span class="token function">showFilter</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token comment">// 禁用过滤器按钮</span></span>
<span class="line"><span class="token variable">$grid</span><span class="token operator">-></span><span class="token function">disableFilterButton</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token comment">// 显示过滤器按钮</span></span>
<span class="line"><span class="token variable">$grid</span><span class="token operator">-></span><span class="token function">showFilterButton</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token variable">$grid</span><span class="token operator">-></span><span class="token function">filter</span><span class="token punctuation">(</span><span class="token keyword">function</span><span class="token punctuation">(</span><span class="token variable">$filter</span><span class="token punctuation">)</span><span class="token punctuation">{</span></span>
<span class="line">    <span class="token comment">// 展开过滤器</span></span>
<span class="line">    <span class="token variable">$filter</span><span class="token operator">-></span><span class="token function">expand</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line">    <span class="token comment">// 在这里添加字段过滤器</span></span>
<span class="line">    <span class="token variable">$filter</span><span class="token operator">-></span><span class="token function">equal</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'id'</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'产品序列号'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line">    <span class="token variable">$filter</span><span class="token operator">-></span><span class="token function">like</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'name'</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'name'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line">    <span class="token operator">...</span></span>
<span class="line"></span>
<span class="line"><span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>禁止自动展开过滤器</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token variable">$grid</span><span class="token operator">-></span><span class="token function">filter</span><span class="token punctuation">(</span><span class="token keyword">function</span><span class="token punctuation">(</span><span class="token variable">$filter</span><span class="token punctuation">)</span><span class="token punctuation">{</span></span>
<span class="line">    <span class="token comment">// 禁止自动展开过滤器</span></span>
<span class="line">    <span class="token variable">$filter</span><span class="token operator">-></span><span class="token function">expand</span><span class="token punctuation">(</span><span class="token constant boolean">false</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line">    <span class="token operator">...</span></span>
<span class="line"></span>
<span class="line"><span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h2 id="过滤器布局" tabindex="-1"><a class="header-anchor" href="#过滤器布局"><span>过滤器布局</span></a></h2>
<p>默认布局方式为<code v-pre>rightSide</code></p>
<h3 id="rightside" tabindex="-1"><a class="header-anchor" href="#rightside"><span>rightSide</span></a></h3>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token keyword">use</span> <span class="token package">Dcat<span class="token punctuation">\</span>Admin<span class="token punctuation">\</span>Grid</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token variable">$grid</span><span class="token operator">-></span><span class="token function">filter</span><span class="token punctuation">(</span><span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token class-name class-name-fully-qualified type-declaration">Grid<span class="token punctuation">\</span>Filter</span> <span class="token variable">$filter</span><span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line">    <span class="token comment">// 更改为 rightSide 布局</span></span>
<span class="line">    <span class="token variable">$filter</span><span class="token operator">-></span><span class="token function">rightSide</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line">    <span class="token operator">...</span></span>
<span class="line"><span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>效果</p>
<p><img src="@source/dcat-admin-2x/assets/images/b8ff1bc1-7838-4e54-9c0a-efab0ea7db24-3g9EdvZTQA.png" alt=""></p>
<h3 id="panel" tabindex="-1"><a class="header-anchor" href="#panel"><span>panel</span></a></h3>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token keyword">use</span> <span class="token package">Dcat<span class="token punctuation">\</span>Admin<span class="token punctuation">\</span>Grid</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token variable">$grid</span><span class="token operator">-></span><span class="token function">filter</span><span class="token punctuation">(</span><span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token class-name class-name-fully-qualified type-declaration">Grid<span class="token punctuation">\</span>Filter</span> <span class="token variable">$filter</span><span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line">    <span class="token comment">// 更改为 panel 布局</span></span>
<span class="line">    <span class="token variable">$filter</span><span class="token operator">-></span><span class="token function">panel</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line">    <span class="token comment">// 注意切换为panel布局方式时需要重新调整表单字段的宽度</span></span>
<span class="line">    <span class="token variable">$filter</span><span class="token operator">-></span><span class="token function">equal</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'id'</span><span class="token punctuation">)</span><span class="token operator">-></span><span class="token function">width</span><span class="token punctuation">(</span><span class="token number">3</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>效果</p>
<p><img src="@source/dcat-admin-2x/assets/images/8a3d22cb-9acb-45d5-b6f8-77aa744572b8-vkPFs0Hnil.png" alt=""></p>
<h3 id="自定义布局-view" tabindex="-1"><a class="header-anchor" href="#自定义布局-view"><span>自定义布局 (view)</span></a></h3>
<p>如果以上的布局无法满足需求，可以通过<code v-pre>view</code>方法自定义过滤器模板</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token variable">$grid</span><span class="token operator">-></span><span class="token function">filter</span><span class="token punctuation">(</span><span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token variable">$filter</span><span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line">    <span class="token variable">$filter</span><span class="token operator">-></span><span class="token function">view</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'xxx'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line">    <span class="token operator">...</span></span>
<span class="line"><span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h2 id="查询类型" tabindex="-1"><a class="header-anchor" href="#查询类型"><span>查询类型</span></a></h2>
<p>目前支持的过滤类型有下面这些:</p>
<h3 id="equal" tabindex="-1"><a class="header-anchor" href="#equal"><span>equal</span></a></h3>
<p><code v-pre>sql: ... WHERE</code>column<code v-pre>= &quot;$input&quot;</code>：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token variable">$filter</span><span class="token operator">-></span><span class="token function">equal</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'column'</span><span class="token punctuation">,</span> <span class="token variable">$label</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><h3 id="notequal" tabindex="-1"><a class="header-anchor" href="#notequal"><span>notEqual</span></a></h3>
<p><code v-pre>sql: ... WHERE</code>column<code v-pre>!= &quot;$input&quot;</code>：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token variable">$filter</span><span class="token operator">-></span><span class="token function">notEqual</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'column'</span><span class="token punctuation">,</span> <span class="token variable">$label</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><h3 id="like" tabindex="-1"><a class="header-anchor" href="#like"><span>like</span></a></h3>
<p><code v-pre>sql: ... WHERE</code>column<code v-pre>LIKE &quot;%$input%&quot;</code>：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token variable">$filter</span><span class="token operator">-></span><span class="token function">like</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'column'</span><span class="token punctuation">,</span> <span class="token variable">$label</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><h3 id="ilike" tabindex="-1"><a class="header-anchor" href="#ilike"><span>ilike</span></a></h3>
<p><code v-pre>sql: ... WHERE</code>column<code v-pre>ILIKE &quot;%$input%&quot;</code>：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token variable">$filter</span><span class="token operator">-></span><span class="token function">ilike</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'column'</span><span class="token punctuation">,</span> <span class="token variable">$label</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><h3 id="startwith" tabindex="-1"><a class="header-anchor" href="#startwith"><span>startWith</span></a></h3>
<p><code v-pre>sql: ... WHERE</code>column<code v-pre>LIKE &quot;$input%&quot;</code>：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token variable">$filter</span><span class="token operator">-></span><span class="token function">startWith</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'column'</span><span class="token punctuation">,</span> <span class="token variable">$label</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token comment">// 如果需要使用“ilike”</span></span>
<span class="line"><span class="token variable">$filter</span><span class="token operator">-></span><span class="token function">startWith</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'column'</span><span class="token punctuation">,</span> <span class="token variable">$label</span><span class="token punctuation">)</span><span class="token operator">-></span><span class="token function">ilike</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="endwith" tabindex="-1"><a class="header-anchor" href="#endwith"><span>endWith</span></a></h3>
<p><code v-pre>sql: ... WHERE</code>column<code v-pre>LIKE &quot;%$input&quot;</code>：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token variable">$filter</span><span class="token operator">-></span><span class="token function">endWith</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'column'</span><span class="token punctuation">,</span> <span class="token variable">$label</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token comment">// 如果需要使用“ilike”</span></span>
<span class="line"><span class="token variable">$filter</span><span class="token operator">-></span><span class="token function">endWith</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'column'</span><span class="token punctuation">,</span> <span class="token variable">$label</span><span class="token punctuation">)</span><span class="token operator">-></span><span class="token function">ilike</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="gt" tabindex="-1"><a class="header-anchor" href="#gt"><span>gt</span></a></h3>
<p><code v-pre>sql: ... WHERE</code>column<code v-pre>&gt; &quot;$input&quot;</code>：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token variable">$filter</span><span class="token operator">-></span><span class="token function">gt</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'column'</span><span class="token punctuation">,</span> <span class="token variable">$label</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><h3 id="lt" tabindex="-1"><a class="header-anchor" href="#lt"><span>lt</span></a></h3>
<p><code v-pre>sql: ... WHERE</code>column<code v-pre>&lt; &quot;$input&quot;</code>：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token variable">$filter</span><span class="token operator">-></span><span class="token function">lt</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'column'</span><span class="token punctuation">,</span> <span class="token variable">$label</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><h3 id="ngt" tabindex="-1"><a class="header-anchor" href="#ngt"><span>ngt</span></a></h3>
<p><code v-pre>sql: ... WHERE</code>column<code v-pre>&lt;= &quot;$input&quot;</code>：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token variable">$filter</span><span class="token operator">-></span><span class="token function">ngt</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'column'</span><span class="token punctuation">,</span> <span class="token variable">$label</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><h3 id="nlt" tabindex="-1"><a class="header-anchor" href="#nlt"><span>nlt</span></a></h3>
<p><code v-pre>sql: ... WHERE</code>column<code v-pre>&gt;= &quot;$input&quot;</code>：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token variable">$filter</span><span class="token operator">-></span><span class="token function">nlt</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'column'</span><span class="token punctuation">,</span> <span class="token variable">$label</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><h3 id="between" tabindex="-1"><a class="header-anchor" href="#between"><span>between</span></a></h3>
<p><code v-pre>sql: ... WHERE</code>column<code v-pre>BETWEEN &quot;$start&quot; AND &quot;$end&quot;</code>：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token variable">$filter</span><span class="token operator">-></span><span class="token function">between</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'column'</span><span class="token punctuation">,</span> <span class="token variable">$label</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token comment">// 设置datetime类型</span></span>
<span class="line"><span class="token variable">$filter</span><span class="token operator">-></span><span class="token function">between</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'column'</span><span class="token punctuation">,</span> <span class="token variable">$label</span><span class="token punctuation">)</span><span class="token operator">-></span><span class="token function">datetime</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token comment">// 设置time类型</span></span>
<span class="line"><span class="token variable">$filter</span><span class="token operator">-></span><span class="token function">between</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'column'</span><span class="token punctuation">,</span> <span class="token variable">$label</span><span class="token punctuation">)</span><span class="token operator">-></span><span class="token function">time</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="in" tabindex="-1"><a class="header-anchor" href="#in"><span>in</span></a></h3>
<p><code v-pre>sql: ... WHERE</code>column<code v-pre>in (...$inputs)</code>：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token variable">$filter</span><span class="token operator">-></span><span class="token function">in</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'column'</span><span class="token punctuation">,</span> <span class="token variable">$label</span><span class="token punctuation">)</span><span class="token operator">-></span><span class="token function">multipleSelect</span><span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token string single-quoted-string">'key'</span> <span class="token operator">=></span> <span class="token string single-quoted-string">'value'</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><h3 id="notin" tabindex="-1"><a class="header-anchor" href="#notin"><span>notIn</span></a></h3>
<p><code v-pre>sql: ... WHERE</code>column<code v-pre>not in (...$inputs)</code>：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token variable">$filter</span><span class="token operator">-></span><span class="token function">notIn</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'column'</span><span class="token punctuation">,</span> <span class="token variable">$label</span><span class="token punctuation">)</span><span class="token operator">-></span><span class="token function">multipleSelect</span><span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token string single-quoted-string">'key'</span> <span class="token operator">=></span> <span class="token string single-quoted-string">'value'</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><h3 id="date" tabindex="-1"><a class="header-anchor" href="#date"><span>date</span></a></h3>
<p><code v-pre>sql: ... WHERE DATE(</code>column<code v-pre>) = &quot;$input&quot;</code>：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token variable">$filter</span><span class="token operator">-></span><span class="token function">date</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'column'</span><span class="token punctuation">,</span> <span class="token variable">$label</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><h3 id="day" tabindex="-1"><a class="header-anchor" href="#day"><span>day</span></a></h3>
<p><code v-pre>sql: ... WHERE DAY(</code>column<code v-pre>) = &quot;$input&quot;</code>：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token variable">$filter</span><span class="token operator">-></span><span class="token function">day</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'column'</span><span class="token punctuation">,</span> <span class="token variable">$label</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><h3 id="month" tabindex="-1"><a class="header-anchor" href="#month"><span>month</span></a></h3>
<p><code v-pre>sql: ... WHERE MONTH(</code>column<code v-pre>) = &quot;$input&quot;</code>：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token variable">$filter</span><span class="token operator">-></span><span class="token function">month</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'column'</span><span class="token punctuation">,</span> <span class="token variable">$label</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><h3 id="year" tabindex="-1"><a class="header-anchor" href="#year"><span>year</span></a></h3>
<p><code v-pre>sql: ... WHERE YEAR(</code>column<code v-pre>) = &quot;$input&quot;</code>：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token variable">$filter</span><span class="token operator">-></span><span class="token function">year</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'column'</span><span class="token punctuation">,</span> <span class="token variable">$label</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><h3 id="findinset" tabindex="-1"><a class="header-anchor" href="#findinset"><span>findInSet</span></a></h3>
<p><code v-pre>sql: ... WHERE FIND_IN_SET(&quot;$input&quot;, $column)</code>：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token variable">$filter</span><span class="token operator">-></span><span class="token function">findInSet</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'column'</span><span class="token punctuation">,</span> <span class="token variable">$label</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><h3 id="复杂查询where" tabindex="-1"><a class="header-anchor" href="#复杂查询where"><span>复杂查询where</span></a></h3>
<p>可以用where来构建比较复杂的查询过滤</p>
<p><code v-pre>sql: ... WHERE</code>title<code v-pre>LIKE &quot;%$input&quot; OR</code>content<code v-pre>LIKE &quot;%$input&quot;</code>：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token variable">$filter</span><span class="token operator">-></span><span class="token function">where</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'search'</span><span class="token punctuation">,</span> <span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token variable">$query</span><span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line"></span>
<span class="line">    <span class="token variable">$query</span><span class="token operator">-></span><span class="token function">where</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'title'</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'like'</span><span class="token punctuation">,</span> <span class="token string double-quoted-string">"%<span class="token interpolation"><span class="token punctuation">{</span><span class="token variable">$this</span><span class="token operator">-></span><span class="token property">input</span><span class="token punctuation">}</span></span>%"</span><span class="token punctuation">)</span></span>
<span class="line">        <span class="token operator">-></span><span class="token function">orWhere</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'content'</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'like'</span><span class="token punctuation">,</span> <span class="token string double-quoted-string">"%<span class="token interpolation"><span class="token punctuation">{</span><span class="token variable">$this</span><span class="token operator">-></span><span class="token property">input</span><span class="token punctuation">}</span></span>%"</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p><code v-pre>sql: ... WHERE</code>rate<code v-pre>&gt;= 6 AND</code>created_at<code v-pre>= {$input}</code>:</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token variable">$filter</span><span class="token operator">-></span><span class="token function">where</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'Text'</span><span class="token punctuation">,</span> <span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token variable">$query</span><span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line"></span>
<span class="line">    <span class="token variable">$query</span><span class="token operator">-></span><span class="token function">whereRaw</span><span class="token punctuation">(</span><span class="token string double-quoted-string">"`rate` >= 6 AND `created_at` = <span class="token interpolation"><span class="token punctuation">{</span><span class="token variable">$this</span><span class="token operator">-></span><span class="token property">input</span><span class="token punctuation">}</span></span>"</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>关系查询，查询对应关系<code v-pre>profile</code>的字段：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token variable">$filter</span><span class="token operator">-></span><span class="token function">where</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'mobile'</span><span class="token punctuation">,</span> <span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token variable">$query</span><span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line"></span>
<span class="line">    <span class="token variable">$query</span><span class="token operator">-></span><span class="token function">whereHas</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'profile'</span><span class="token punctuation">,</span> <span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token variable">$query</span><span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line">        <span class="token variable">$query</span><span class="token operator">-></span><span class="token function">where</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'address'</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'like'</span><span class="token punctuation">,</span> <span class="token string double-quoted-string">"%<span class="token interpolation"><span class="token punctuation">{</span><span class="token variable">$this</span><span class="token operator">-></span><span class="token property">input</span><span class="token punctuation">}</span></span>%"</span><span class="token punctuation">)</span><span class="token operator">-></span><span class="token function">orWhere</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'email'</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'like'</span><span class="token punctuation">,</span> <span class="token string double-quoted-string">"%<span class="token interpolation"><span class="token punctuation">{</span><span class="token variable">$this</span><span class="token operator">-></span><span class="token property">input</span><span class="token punctuation">}</span></span>%"</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line">    <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'地址或手机号'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="复杂范围查询wherebetween" tabindex="-1"><a class="header-anchor" href="#复杂范围查询wherebetween"><span>复杂范围查询whereBetween</span></a></h3>
<p>通过<code v-pre>whereBetween</code>可以自定义范围查询</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token variable">$filter</span><span class="token operator">-></span><span class="token function">whereBetween</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'created_at'</span><span class="token punctuation">,</span> <span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token variable">$q</span><span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line">    <span class="token variable">$start</span> <span class="token operator">=</span> <span class="token variable">$this</span><span class="token operator">-></span><span class="token property">input</span><span class="token punctuation">[</span><span class="token string single-quoted-string">'start'</span><span class="token punctuation">]</span> <span class="token operator">??</span> <span class="token constant">null</span><span class="token punctuation">;</span></span>
<span class="line">    <span class="token variable">$end</span> <span class="token operator">=</span> <span class="token variable">$this</span><span class="token operator">-></span><span class="token property">input</span><span class="token punctuation">[</span><span class="token string single-quoted-string">'end'</span><span class="token punctuation">]</span> <span class="token operator">??</span> <span class="token constant">null</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line">    <span class="token variable">$q</span><span class="token operator">-></span><span class="token function">whereHas</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'goods'</span><span class="token punctuation">,</span> <span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token variable">$q</span><span class="token punctuation">)</span> <span class="token keyword">use</span> <span class="token punctuation">(</span><span class="token variable">$start</span><span class="token punctuation">,</span><span class="token variable">$end</span><span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line">        <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token variable">$start</span> <span class="token operator">!==</span> <span class="token constant">null</span><span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line">            <span class="token variable">$q</span><span class="token operator">-></span><span class="token function">where</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'price'</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'>='</span><span class="token punctuation">,</span> <span class="token variable">$start</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line">        <span class="token punctuation">}</span></span>
<span class="line"></span>
<span class="line">        <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token variable">$end</span> <span class="token operator">!==</span> <span class="token constant">null</span><span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line">            <span class="token variable">$q</span><span class="token operator">-></span><span class="token function">where</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'price'</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'&lt;='</span><span class="token punctuation">,</span> <span class="token variable">$end</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line">        <span class="token punctuation">}</span></span>
<span class="line">    <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>       </span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>同时这个方法也支持时间日期范围查询</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token variable">$filter</span><span class="token operator">-></span><span class="token function">whereBetween</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'created_at'</span><span class="token punctuation">,</span> <span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token variable">$q</span><span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line">    <span class="token operator">...</span></span>
<span class="line"><span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token operator">-></span><span class="token function">datetime</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> </span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="过滤器组group" tabindex="-1"><a class="header-anchor" href="#过滤器组group"><span>过滤器组group</span></a></h3>
<p>有时候对同一个字段要设置多种筛选方式，可以通过下面的方式实现</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token variable">$filter</span><span class="token operator">-></span><span class="token function">group</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'rate'</span><span class="token punctuation">,</span> <span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token variable">$group</span><span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line">    <span class="token variable">$group</span><span class="token operator">-></span><span class="token function">gt</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'大于'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line">    <span class="token variable">$group</span><span class="token operator">-></span><span class="token function">lt</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'小于'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line">    <span class="token variable">$group</span><span class="token operator">-></span><span class="token function">nlt</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'不小于'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line">    <span class="token variable">$group</span><span class="token operator">-></span><span class="token function">ngt</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'不大于'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line">    <span class="token variable">$group</span><span class="token operator">-></span><span class="token function">equal</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'等于'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>有下面的几个方法可以调用</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token comment">// 等于</span></span>
<span class="line"><span class="token variable">$group</span><span class="token operator">-></span><span class="token function">equal</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token comment">// 不等于</span></span>
<span class="line"><span class="token variable">$group</span><span class="token operator">-></span><span class="token function">notEqual</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token comment">// 大于</span></span>
<span class="line"><span class="token variable">$group</span><span class="token operator">-></span><span class="token function">gt</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token comment">// 小于</span></span>
<span class="line"><span class="token variable">$group</span><span class="token operator">-></span><span class="token function">lt</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token comment">// 大于等于</span></span>
<span class="line"><span class="token variable">$group</span><span class="token operator">-></span><span class="token function">nlt</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token comment">// 小于等于</span></span>
<span class="line"><span class="token variable">$group</span><span class="token operator">-></span><span class="token function">ngt</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token comment">// 匹配</span></span>
<span class="line"><span class="token variable">$group</span><span class="token operator">-></span><span class="token function">match</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token comment">// 复杂条件</span></span>
<span class="line"><span class="token variable">$group</span><span class="token operator">-></span><span class="token function">where</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token comment">// like查询</span></span>
<span class="line"><span class="token variable">$group</span><span class="token operator">-></span><span class="token function">like</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token comment">// like查询</span></span>
<span class="line"><span class="token variable">$group</span><span class="token operator">-></span><span class="token function">contains</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token comment">// ilike查询</span></span>
<span class="line"><span class="token variable">$group</span><span class="token operator">-></span><span class="token function">ilike</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token comment">// 以输入的内容开头</span></span>
<span class="line"><span class="token variable">$group</span><span class="token operator">-></span><span class="token function">startWith</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token comment">// 以输入的内容结尾</span></span>
<span class="line"><span class="token variable">$group</span><span class="token operator">-></span><span class="token function">endWith</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="范围查询scope" tabindex="-1"><a class="header-anchor" href="#范围查询scope"><span>范围查询scope</span></a></h3>
<p>可以把你最常用的查询定义为一个查询范围，它将会出现在筛选按钮的下拉菜单中，下面是几个例子：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token variable">$filter</span><span class="token operator">-></span><span class="token function">scope</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'male'</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'男性'</span><span class="token punctuation">)</span><span class="token operator">-></span><span class="token function">where</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'gender'</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'m'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token comment">// 多条件查询</span></span>
<span class="line"><span class="token variable">$filter</span><span class="token operator">-></span><span class="token function">scope</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'new'</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'最近修改'</span><span class="token punctuation">)</span></span>
<span class="line">    <span class="token operator">-></span><span class="token function">whereDate</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'created_at'</span><span class="token punctuation">,</span> <span class="token function">date</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'Y-m-d'</span><span class="token punctuation">)</span><span class="token punctuation">)</span></span>
<span class="line">    <span class="token operator">-></span><span class="token function">orWhere</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'updated_at'</span><span class="token punctuation">,</span> <span class="token function">date</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'Y-m-d'</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token comment">// 关联关系查询</span></span>
<span class="line"><span class="token variable">$filter</span><span class="token operator">-></span><span class="token function">scope</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'address'</span><span class="token punctuation">)</span><span class="token operator">-></span><span class="token function">whereHas</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'profile'</span><span class="token punctuation">,</span> <span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token variable">$query</span><span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line">    <span class="token variable">$query</span><span class="token operator">-></span><span class="token function">whereNotNull</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'address'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token variable">$filter</span><span class="token operator">-></span><span class="token function">scope</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'trashed'</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'被软删除的数据'</span><span class="token punctuation">)</span><span class="token operator">-></span><span class="token function">onlyTrashed</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>scope方法第一个参数为查询的key, 会出现的url参数中，第二个参数是下拉菜单项的label, 如果不填，第一个参数会作为label显示</p>
<p>scope方法可以链式调用任何eloquent查询条件，效果参考Demo</p>
<h2 id="表单类型" tabindex="-1"><a class="header-anchor" href="#表单类型"><span>表单类型</span></a></h2>
<h3 id="text" tabindex="-1"><a class="header-anchor" href="#text"><span>text</span></a></h3>
<p>表单类型默认是<code v-pre>text input</code>，可以设置<code v-pre>placeholder</code>：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token variable">$filter</span><span class="token operator">-></span><span class="token function">equal</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'column'</span><span class="token punctuation">)</span><span class="token operator">-></span><span class="token function">placeholder</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'请输入。。。'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><p>也可以通过下面的一些方法来限制用户输入格式：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token variable">$filter</span><span class="token operator">-></span><span class="token function">equal</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'column'</span><span class="token punctuation">)</span><span class="token operator">-></span><span class="token function">url</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token variable">$filter</span><span class="token operator">-></span><span class="token function">equal</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'column'</span><span class="token punctuation">)</span><span class="token operator">-></span><span class="token function">email</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token variable">$filter</span><span class="token operator">-></span><span class="token function">equal</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'column'</span><span class="token punctuation">)</span><span class="token operator">-></span><span class="token function">integer</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token variable">$filter</span><span class="token operator">-></span><span class="token function">equal</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'column'</span><span class="token punctuation">)</span><span class="token operator">-></span><span class="token function">ip</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token variable">$filter</span><span class="token operator">-></span><span class="token function">equal</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'column'</span><span class="token punctuation">)</span><span class="token operator">-></span><span class="token function">mac</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token variable">$filter</span><span class="token operator">-></span><span class="token function">equal</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'column'</span><span class="token punctuation">)</span><span class="token operator">-></span><span class="token function">mobile</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token comment">// $options 参考 https://github.com/RobinHerbots/Inputmask/blob/4.x/README_numeric.md</span></span>
<span class="line"><span class="token variable">$filter</span><span class="token operator">-></span><span class="token function">equal</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'column'</span><span class="token punctuation">)</span><span class="token operator">-></span><span class="token function">decimal</span><span class="token punctuation">(</span><span class="token variable">$options</span> <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token comment">// $options 参考 https://github.com/RobinHerbots/Inputmask/blob/4.x/README_numeric.md</span></span>
<span class="line"><span class="token variable">$filter</span><span class="token operator">-></span><span class="token function">equal</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'column'</span><span class="token punctuation">)</span><span class="token operator">-></span><span class="token function">currency</span><span class="token punctuation">(</span><span class="token variable">$options</span> <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token comment">// $options 参考 https://github.com/RobinHerbots/Inputmask/blob/4.x/README_numeric.md</span></span>
<span class="line"><span class="token variable">$filter</span><span class="token operator">-></span><span class="token function">equal</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'column'</span><span class="token punctuation">)</span><span class="token operator">-></span><span class="token function">percentage</span><span class="token punctuation">(</span><span class="token variable">$options</span> <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token comment">// $options 参考 https://github.com/RobinHerbots/Inputmask, $icon为input前面的图标</span></span>
<span class="line"><span class="token variable">$filter</span><span class="token operator">-></span><span class="token function">equal</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'column'</span><span class="token punctuation">)</span><span class="token operator">-></span><span class="token function">inputmask</span><span class="token punctuation">(</span><span class="token variable">$options</span> <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token variable">$icon</span> <span class="token operator">=</span> <span class="token string single-quoted-string">'pencil'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="表格选择器-selecttable" tabindex="-1"><a class="header-anchor" href="#表格选择器-selecttable"><span>表格选择器 (selectTable)</span></a></h3>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token keyword">use</span> <span class="token package">App<span class="token punctuation">\</span>Admin<span class="token punctuation">\</span>Renderable<span class="token punctuation">\</span>UserTable</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token keyword">use</span> <span class="token package">Dcat<span class="token punctuation">\</span>Admin<span class="token punctuation">\</span>Models<span class="token punctuation">\</span>Administrator</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token variable">$filter</span><span class="token operator">-></span><span class="token function">equal</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'user_id'</span><span class="token punctuation">)</span></span>
<span class="line">    <span class="token operator">-></span><span class="token function">selectTable</span><span class="token punctuation">(</span><span class="token class-name static-context">UserTable</span><span class="token operator">::</span><span class="token function">make</span><span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token string single-quoted-string">'id'</span> <span class="token operator">=></span> <span class="token operator">...</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token comment">// 设置渲染类实例，并传递自定义参数</span></span>
<span class="line">    <span class="token operator">-></span><span class="token function">title</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'弹窗标题'</span><span class="token punctuation">)</span></span>
<span class="line">    <span class="token operator">-></span><span class="token function">dialogWidth</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'50%'</span><span class="token punctuation">)</span> <span class="token comment">// 弹窗宽度，默认 800px</span></span>
<span class="line">    <span class="token operator">-></span><span class="token function">model</span><span class="token punctuation">(</span><span class="token class-name static-context">Administrator</span><span class="token operator">::</span><span class="token keyword">class</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'id'</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'name'</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// 设置编辑数据显示</span></span>
<span class="line"></span>
<span class="line"><span class="token comment">// 上面的代码等同于</span></span>
<span class="line"><span class="token variable">$filter</span><span class="token operator">-></span><span class="token function">equal</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'user_id'</span><span class="token punctuation">)</span></span>
<span class="line">    <span class="token operator">-></span><span class="token function">selectTable</span><span class="token punctuation">(</span><span class="token class-name static-context">UserTable</span><span class="token operator">::</span><span class="token function">make</span><span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token string single-quoted-string">'id'</span> <span class="token operator">=></span> <span class="token operator">...</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token comment">// 设置渲染类实例，并传递自定义参数</span></span>
<span class="line">    <span class="token operator">-></span><span class="token function">options</span><span class="token punctuation">(</span><span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token variable">$v</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token comment">// 设置编辑数据显示</span></span>
<span class="line">        <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token operator">!</span> <span class="token variable">$v</span><span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line">            <span class="token keyword">return</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">;</span></span>
<span class="line">        <span class="token punctuation">}</span></span>
<span class="line"></span>
<span class="line">        <span class="token keyword">return</span> <span class="token class-name static-context">Administrator</span><span class="token operator">::</span><span class="token function">find</span><span class="token punctuation">(</span><span class="token variable">$v</span><span class="token punctuation">)</span><span class="token operator">-></span><span class="token function">pluck</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'name'</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'id'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line">    <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>定义渲染类如下，需要继承<code v-pre>Dcat\Admin\Grid\LazyRenderable</code></p>
<blockquote>
<p>{tip} 这里使用了数据表格异步加载功能，详细用法请参考<a href="https://learnku.com/docs/dcat-admin/2.x/asynchronous-loading/9327" target="_blank" rel="noopener noreferrer">异步加载</a></p>
</blockquote>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token php language-php"><span class="token delimiter important">&lt;?php</span></span>
<span class="line"></span>
<span class="line"><span class="token keyword">namespace</span> <span class="token package">App<span class="token punctuation">\</span>Admin<span class="token punctuation">\</span>Renderable</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token keyword">use</span> <span class="token package">Dcat<span class="token punctuation">\</span>Admin<span class="token punctuation">\</span>Grid</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token keyword">use</span> <span class="token package">Dcat<span class="token punctuation">\</span>Admin<span class="token punctuation">\</span>Grid<span class="token punctuation">\</span>LazyRenderable</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token keyword">use</span> <span class="token package">Dcat<span class="token punctuation">\</span>Admin<span class="token punctuation">\</span>Models<span class="token punctuation">\</span>Administrator</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token keyword">class</span> <span class="token class-name-definition class-name">UserTable</span> <span class="token keyword">extends</span> <span class="token class-name">LazyRenderable</span></span>
<span class="line"><span class="token punctuation">{</span></span>
<span class="line">    <span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function-definition function">grid</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token class-name return-type">Grid</span></span>
<span class="line">    <span class="token punctuation">{</span></span>
<span class="line">        <span class="token comment">// 获取外部传递的参数</span></span>
<span class="line">        <span class="token variable">$id</span> <span class="token operator">=</span> <span class="token variable">$this</span><span class="token operator">-></span><span class="token property">id</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line">        <span class="token keyword">return</span> <span class="token class-name static-context">Grid</span><span class="token operator">::</span><span class="token function">make</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">Administrator</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token class-name type-declaration">Grid</span> <span class="token variable">$grid</span><span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line">            <span class="token variable">$grid</span><span class="token operator">-></span><span class="token function">column</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'id'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line">            <span class="token variable">$grid</span><span class="token operator">-></span><span class="token function">column</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'username'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line">            <span class="token variable">$grid</span><span class="token operator">-></span><span class="token function">column</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'name'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line">            <span class="token variable">$grid</span><span class="token operator">-></span><span class="token function">column</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'created_at'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line">            <span class="token variable">$grid</span><span class="token operator">-></span><span class="token function">column</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'updated_at'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line">            <span class="token comment">// 指定行选择器选中时显示的值的字段名称</span></span>
<span class="line">            <span class="token comment">// 指定行选择器选中时显示的值的字段名称</span></span>
<span class="line">            <span class="token comment">// 指定行选择器选中时显示的值的字段名称</span></span>
<span class="line">            <span class="token comment">// 如果表格数据中带有 “name”、“title”或“username”字段，则可以不用设置</span></span>
<span class="line">            <span class="token variable">$grid</span><span class="token operator">-></span><span class="token function">rowSelector</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">-></span><span class="token function">titleColumn</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'username'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line">            <span class="token variable">$grid</span><span class="token operator">-></span><span class="token function">quickSearch</span><span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token string single-quoted-string">'id'</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'username'</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'name'</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line">            <span class="token variable">$grid</span><span class="token operator">-></span><span class="token function">paginate</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line">            <span class="token variable">$grid</span><span class="token operator">-></span><span class="token function">disableActions</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line">            <span class="token variable">$grid</span><span class="token operator">-></span><span class="token function">filter</span><span class="token punctuation">(</span><span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token class-name class-name-fully-qualified type-declaration">Grid<span class="token punctuation">\</span>Filter</span> <span class="token variable">$filter</span><span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line">                <span class="token variable">$filter</span><span class="token operator">-></span><span class="token function">like</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'username'</span><span class="token punctuation">)</span><span class="token operator">-></span><span class="token function">width</span><span class="token punctuation">(</span><span class="token number">4</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line">                <span class="token variable">$filter</span><span class="token operator">-></span><span class="token function">like</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'name'</span><span class="token punctuation">)</span><span class="token operator">-></span><span class="token function">width</span><span class="token punctuation">(</span><span class="token number">4</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line">            <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line">        <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line">    <span class="token punctuation">}</span></span>
<span class="line"><span class="token punctuation">}</span></span>
<span class="line"></span></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h4 id="多选-multipleselecttable" tabindex="-1"><a class="header-anchor" href="#多选-multipleselecttable"><span>多选（multipleSelectTable）</span></a></h4>
<p>多选的用法与上述<code v-pre>selectTable</code>方法一致</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token variable">$filter</span><span class="token operator">-></span><span class="token function">in</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'user_id'</span><span class="token punctuation">)</span></span>
<span class="line">    <span class="token operator">-></span><span class="token function">multipleSelectTable</span><span class="token punctuation">(</span><span class="token class-name static-context">UserTable</span><span class="token operator">::</span><span class="token function">make</span><span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token string single-quoted-string">'id'</span> <span class="token operator">=></span> <span class="token variable">$form</span><span class="token operator">-></span><span class="token function">getKey</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token comment">// 设置渲染类实例，并传递自定义参数</span></span>
<span class="line">    <span class="token operator">-></span><span class="token function">max</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">)</span> <span class="token comment">// 最多选择 10 个选项，不传则不限制</span></span>
<span class="line">    <span class="token operator">-></span><span class="token function">model</span><span class="token punctuation">(</span><span class="token class-name static-context">Administrator</span><span class="token operator">::</span><span class="token keyword">class</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'id'</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'name'</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// 设置编辑数据显示</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="select" tabindex="-1"><a class="header-anchor" href="#select"><span>select</span></a></h3>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token variable">$filter</span><span class="token operator">-></span><span class="token function">equal</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'column'</span><span class="token punctuation">)</span><span class="token operator">-></span><span class="token function">select</span><span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token string single-quoted-string">'key'</span> <span class="token operator">=></span> <span class="token string single-quoted-string">'value'</span><span class="token operator">...</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token comment">// 或者从api获取数据，api的格式参考model-form的select组件</span></span>
<span class="line"><span class="token variable">$filter</span><span class="token operator">-></span><span class="token function">equal</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'column'</span><span class="token punctuation">)</span><span class="token operator">-></span><span class="token function">select</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'api/users'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="multipleselect" tabindex="-1"><a class="header-anchor" href="#multipleselect"><span>multipleSelect</span></a></h3>
<p>一般用来配合<code v-pre>in</code>和<code v-pre>notIn</code>两个需要查询数组的查询类型使用，也可以在<code v-pre>where</code>类型的查询中使用：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token variable">$filter</span><span class="token operator">-></span><span class="token function">in</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'column'</span><span class="token punctuation">)</span><span class="token operator">-></span><span class="token function">multipleSelect</span><span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token string single-quoted-string">'key'</span> <span class="token operator">=></span> <span class="token string single-quoted-string">'value'</span><span class="token operator">...</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token comment">// 或者从api获取数据，api的格式参考model-form的multipleSelect组件</span></span>
<span class="line"><span class="token variable">$filter</span><span class="token operator">-></span><span class="token function">in</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'column'</span><span class="token punctuation">)</span><span class="token operator">-></span><span class="token function">multipleSelect</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'api/users'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="datetime" tabindex="-1"><a class="header-anchor" href="#datetime"><span>datetime</span></a></h3>
<p>通过日期时间组件来查询，<code v-pre>$options</code>的参数和值参考<a href="http://eonasdan.github.io/bootstrap-datetimepicker/Options/" target="_blank" rel="noopener noreferrer">bootstrap-datetimepicker</a></p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token variable">$filter</span><span class="token operator">-></span><span class="token function">equal</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'column'</span><span class="token punctuation">)</span><span class="token operator">-></span><span class="token function">datetime</span><span class="token punctuation">(</span><span class="token variable">$options</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token comment">// `date()` 相当于 `datetime(['format' => 'YYYY-MM-DD'])`</span></span>
<span class="line"><span class="token variable">$filter</span><span class="token operator">-></span><span class="token function">equal</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'column'</span><span class="token punctuation">)</span><span class="token operator">-></span><span class="token function">date</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token comment">// `time()` 相当于 `datetime(['format' => 'HH:mm:ss'])`</span></span>
<span class="line"><span class="token variable">$filter</span><span class="token operator">-></span><span class="token function">equal</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'column'</span><span class="token punctuation">)</span><span class="token operator">-></span><span class="token function">time</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token comment">// `day()` 相当于 `datetime(['format' => 'DD'])`</span></span>
<span class="line"><span class="token variable">$filter</span><span class="token operator">-></span><span class="token function">equal</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'column'</span><span class="token punctuation">)</span><span class="token operator">-></span><span class="token function">day</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token comment">// `month()` 相当于 `datetime(['format' => 'MM'])`</span></span>
<span class="line"><span class="token variable">$filter</span><span class="token operator">-></span><span class="token function">equal</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'column'</span><span class="token punctuation">)</span><span class="token operator">-></span><span class="token function">month</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token comment">// `year()` 相当于 `datetime(['format' => 'YYYY'])`</span></span>
<span class="line"><span class="token variable">$filter</span><span class="token operator">-></span><span class="token function">equal</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'column'</span><span class="token punctuation">)</span><span class="token operator">-></span><span class="token function">year</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>如果你的时间日期字段在数据库中存储的是时间戳类型，那么可以通过<code v-pre>toTimestamp</code>方法把表单的值转化为时间戳</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token variable">$filter</span><span class="token operator">-></span><span class="token function">equal</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'column'</span><span class="token punctuation">)</span><span class="token operator">-></span><span class="token function">datetime</span><span class="token punctuation">(</span><span class="token variable">$options</span><span class="token punctuation">)</span><span class="token operator">-></span><span class="token function">toTimestamp</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><h2 id="常用方法" tabindex="-1"><a class="header-anchor" href="#常用方法"><span>常用方法</span></a></h2>
<h3 id="过滤器宽度-width" tabindex="-1"><a class="header-anchor" href="#过滤器宽度-width"><span>过滤器宽度 (width)</span></a></h3>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token comment">// 设置为“1-12”之间的值，默认值是“3”</span></span>
<span class="line"><span class="token variable">$filter</span><span class="token operator">-></span><span class="token function">equal</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'column'</span><span class="token punctuation">)</span><span class="token operator">-></span><span class="token function">width</span><span class="token punctuation">(</span><span class="token number">3</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token comment">// 也可以写死宽度</span></span>
<span class="line"><span class="token variable">$filter</span><span class="token operator">-></span><span class="token function">equal</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'column'</span><span class="token punctuation">)</span><span class="token operator">-></span><span class="token function">width</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'250px'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="设置默认值-default" tabindex="-1"><a class="header-anchor" href="#设置默认值-default"><span>设置默认值 (default)</span></a></h3>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token variable">$filter</span><span class="token operator">-></span><span class="token function">equal</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'column'</span><span class="token punctuation">)</span><span class="token operator">-></span><span class="token function">default</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'text'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token variable">$filter</span><span class="token operator">-></span><span class="token function">equal</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'column'</span><span class="token punctuation">)</span><span class="token operator">-></span><span class="token function">select</span><span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token number">0</span> <span class="token operator">=></span> <span class="token string single-quoted-string">'PHP'</span><span class="token punctuation">,</span> <span class="token number">1</span> <span class="token operator">=></span> <span class="token string single-quoted-string">'Java'</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token operator">-></span><span class="token function">default</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token comment">// 使用 between 过滤器时，提供 start 和 end 为键的数组</span></span>
<span class="line"><span class="token variable">$filter</span><span class="token operator">-></span><span class="token function">between</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'column'</span><span class="token punctuation">)</span><span class="token operator">-></span><span class="token function">default</span><span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token string single-quoted-string">'start'</span> <span class="token operator">=></span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'end'</span> <span class="token operator">=></span> <span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token variable">$filter</span><span class="token operator">-></span><span class="token function">between</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'column'</span><span class="token punctuation">)</span><span class="token operator">-></span><span class="token function">date</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">-></span><span class="token function">default</span><span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token string single-quoted-string">'start'</span> <span class="token operator">=></span> <span class="token string single-quoted-string">'2000-01-01'</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'end'</span> <span class="token operator">=></span> <span class="token string single-quoted-string">'2000-01-01'</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="展开过滤器-expand" tabindex="-1"><a class="header-anchor" href="#展开过滤器-expand"><span>展开过滤器 (expand)</span></a></h3>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token variable">$filter</span><span class="token operator">-></span><span class="token function">expand</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token variable">$filter</span><span class="token operator">-></span><span class="token function">equal</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'column'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token operator">...</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="不显示过滤器input输入框的边框" tabindex="-1"><a class="header-anchor" href="#不显示过滤器input输入框的边框"><span>不显示过滤器input输入框的边框</span></a></h3>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token variable">$filter</span><span class="token operator">-></span><span class="token function">withoutInputBorder</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token variable">$filter</span><span class="token operator">-></span><span class="token function">equal</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'column'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token operator">...</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="设置过滤器容器样式" tabindex="-1"><a class="header-anchor" href="#设置过滤器容器样式"><span>设置过滤器容器样式</span></a></h3>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token variable">$filter</span><span class="token operator">-></span><span class="token function">style</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'padding:0'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token variable">$filter</span><span class="token operator">-></span><span class="token function">equal</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'column'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token operator">...</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="设置过滤器容器padding" tabindex="-1"><a class="header-anchor" href="#设置过滤器容器padding"><span>设置过滤器容器padding</span></a></h3>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token variable">$filter</span><span class="token operator">-></span><span class="token function">padding</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'10px'</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'10px'</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'10px'</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'10px'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token variable">$filter</span><span class="token operator">-></span><span class="token function">equal</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'column'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token operator">...</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="忽略筛选项-ignore" tabindex="-1"><a class="header-anchor" href="#忽略筛选项-ignore"><span>忽略筛选项 (ignore)</span></a></h3>
<p>通过<code v-pre>ignore</code>方法可以在提交表单时忽略当前筛选项</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token variable">$filter</span><span class="token operator">-></span><span class="token function">equal</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'column'</span><span class="token punctuation">)</span><span class="token operator">-></span><span class="token function">ignore</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><h2 id="关联关系字段查询" tabindex="-1"><a class="header-anchor" href="#关联关系字段查询"><span>关联关系字段查询</span></a></h2>
<p>假设你的模型如下</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token keyword">class</span> <span class="token class-name-definition class-name">User</span> <span class="token keyword">extends</span> <span class="token class-name">Model</span></span>
<span class="line"><span class="token punctuation">{</span></span>
<span class="line">    <span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function-definition function">profile</span><span class="token punctuation">(</span><span class="token punctuation">)</span></span>
<span class="line">    <span class="token punctuation">{</span></span>
<span class="line">        <span class="token keyword">return</span> <span class="token variable">$this</span><span class="token operator">-></span><span class="token function">hasOne</span><span class="token punctuation">(</span><span class="token operator">...</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line">    <span class="token punctuation">}</span></span>
<span class="line"></span>
<span class="line">    <span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function-definition function">myPosts</span><span class="token punctuation">(</span><span class="token punctuation">)</span></span>
<span class="line">    <span class="token punctuation">{</span></span>
<span class="line">        <span class="token keyword">return</span> <span class="token variable">$this</span><span class="token operator">-></span><span class="token function">hasMany</span><span class="token punctuation">(</span><span class="token operator">...</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line">    <span class="token punctuation">}</span></span>
<span class="line"><span class="token punctuation">}</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>通过下面的方法可以查询<code v-pre>profiles</code>表的<code v-pre>first_name</code>字段以及<code v-pre>posts</code>表的<code v-pre>title</code>字段</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token variable">$grid</span><span class="token operator">-></span><span class="token function">filter</span><span class="token punctuation">(</span><span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token variable">$filter</span><span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line">    <span class="token variable">$filter</span><span class="token operator">-></span><span class="token function">like</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'profile.first_name'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line">    <span class="token variable">$filter</span><span class="token operator">-></span><span class="token function">like</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'myPosts.title'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>如果安装了 <a href="https://github.com/jqhph/laravel-wherehasin" target="_blank" rel="noopener noreferrer">dcat/laravel-wherehasin</a>，则会优先使用<code v-pre>whereHasIn</code>方法进行查询操作</p>
<h2 id="自定义过滤器" tabindex="-1"><a class="header-anchor" href="#自定义过滤器"><span>自定义过滤器</span></a></h2>
<p>下面通过<code v-pre>between</code>的实现来讲解下怎么自定义过滤器。</p>
<p>首先新建一个过滤器类继承<code v-pre>Dcat\Admin\Grid\Filter\AbstractFilter</code>：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token php language-php"><span class="token delimiter important">&lt;?php</span></span>
<span class="line"></span>
<span class="line"><span class="token keyword">namespace</span> <span class="token package">Dcat<span class="token punctuation">\</span>Admin<span class="token punctuation">\</span>Grid<span class="token punctuation">\</span>Filter</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token keyword">use</span> <span class="token package">Dcat<span class="token punctuation">\</span>Admin<span class="token punctuation">\</span>Admin</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token keyword">use</span> <span class="token package">Dcat<span class="token punctuation">\</span>Admin<span class="token punctuation">\</span>Grid<span class="token punctuation">\</span>Filter<span class="token punctuation">\</span>Presenter<span class="token punctuation">\</span>DateTime</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token keyword">use</span> <span class="token package">Illuminate<span class="token punctuation">\</span>Support<span class="token punctuation">\</span>Arr</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token keyword">class</span> <span class="token class-name-definition class-name">Between</span> <span class="token keyword">extends</span> <span class="token class-name">AbstractFilter</span></span>
<span class="line"><span class="token punctuation">{</span></span>
<span class="line">    <span class="token comment">// 自定义你的过滤器显示模板</span></span>
<span class="line">    <span class="token keyword">protected</span> <span class="token variable">$view</span> <span class="token operator">=</span> <span class="token string single-quoted-string">'admin::filter.between'</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line">    <span class="token comment">// 这个方法用于生成过滤器字段的唯一id</span></span>
<span class="line">    <span class="token comment">// 通过这个唯一id则可以用js代码对其进行操作</span></span>
<span class="line">    <span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function-definition function">formatId</span><span class="token punctuation">(</span><span class="token variable">$column</span><span class="token punctuation">)</span></span>
<span class="line">    <span class="token punctuation">{</span></span>
<span class="line">       <span class="token variable">$id</span>   <span class="token operator">=</span> <span class="token function">str_replace</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'.'</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'_'</span><span class="token punctuation">,</span> <span class="token variable">$column</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line">       <span class="token variable">$name</span> <span class="token operator">=</span> <span class="token variable">$this</span><span class="token operator">-></span><span class="token property">parent</span><span class="token operator">-></span><span class="token function">getGrid</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">-></span><span class="token function">getName</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line">       <span class="token keyword">return</span> <span class="token punctuation">[</span><span class="token string single-quoted-string">'start'</span> <span class="token operator">=></span> <span class="token string double-quoted-string">"<span class="token interpolation"><span class="token punctuation">{</span><span class="token variable">$name</span><span class="token punctuation">}</span></span><span class="token interpolation"><span class="token punctuation">{</span><span class="token variable">$id</span><span class="token punctuation">}</span></span>_start"</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'end'</span> <span class="token operator">=></span> <span class="token string double-quoted-string">"<span class="token interpolation"><span class="token punctuation">{</span><span class="token variable">$name</span><span class="token punctuation">}</span></span><span class="token interpolation"><span class="token punctuation">{</span><span class="token variable">$id</span><span class="token punctuation">}</span></span>_end"</span><span class="token punctuation">]</span><span class="token punctuation">;</span></span>
<span class="line">    <span class="token punctuation">}</span></span>
<span class="line"></span>
<span class="line">    <span class="token comment">// form表单name属性格式化</span></span>
<span class="line">    <span class="token keyword">protected</span> <span class="token keyword">function</span> <span class="token function-definition function">formatName</span><span class="token punctuation">(</span><span class="token variable">$column</span><span class="token punctuation">)</span></span>
<span class="line">    <span class="token punctuation">{</span></span>
<span class="line">        <span class="token variable">$columns</span> <span class="token operator">=</span> <span class="token function">explode</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'.'</span><span class="token punctuation">,</span> <span class="token variable">$column</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line">        <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token function">count</span><span class="token punctuation">(</span><span class="token variable">$columns</span><span class="token punctuation">)</span> <span class="token operator">==</span> <span class="token number">1</span><span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line">            <span class="token variable">$name</span> <span class="token operator">=</span> <span class="token variable">$columns</span><span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">;</span></span>
<span class="line">        <span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span></span>
<span class="line">            <span class="token variable">$name</span> <span class="token operator">=</span> <span class="token function">array_shift</span><span class="token punctuation">(</span><span class="token variable">$columns</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line">            <span class="token keyword">foreach</span> <span class="token punctuation">(</span><span class="token variable">$columns</span> <span class="token keyword">as</span> <span class="token variable">$column</span><span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line">                <span class="token variable">$name</span> <span class="token operator">.=</span> <span class="token string double-quoted-string">"[<span class="token interpolation"><span class="token variable">$column</span></span>]"</span><span class="token punctuation">;</span></span>
<span class="line">            <span class="token punctuation">}</span></span>
<span class="line">        <span class="token punctuation">}</span></span>
<span class="line"></span>
<span class="line">        <span class="token keyword">return</span> <span class="token punctuation">[</span><span class="token string single-quoted-string">'start'</span> <span class="token operator">=></span> <span class="token string double-quoted-string">"<span class="token interpolation"><span class="token punctuation">{</span><span class="token variable">$name</span><span class="token punctuation">}</span></span>[start]"</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'end'</span> <span class="token operator">=></span> <span class="token string double-quoted-string">"<span class="token interpolation"><span class="token punctuation">{</span><span class="token variable">$name</span><span class="token punctuation">}</span></span>[end]"</span><span class="token punctuation">]</span><span class="token punctuation">;</span></span>
<span class="line">    <span class="token punctuation">}</span></span>
<span class="line"></span>
<span class="line">    <span class="token comment">// 创建条件</span></span>
<span class="line">    <span class="token comment">// 这里构建的条件支持`Laravel query builder`即可。</span></span>
<span class="line">    <span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function-definition function">condition</span><span class="token punctuation">(</span><span class="token variable">$inputs</span><span class="token punctuation">)</span></span>
<span class="line">    <span class="token punctuation">{</span></span>
<span class="line">        <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token operator">!</span><span class="token class-name static-context">Arr</span><span class="token operator">::</span><span class="token function">has</span><span class="token punctuation">(</span><span class="token variable">$inputs</span><span class="token punctuation">,</span> <span class="token variable">$this</span><span class="token operator">-></span><span class="token property">column</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line">            <span class="token keyword">return</span><span class="token punctuation">;</span></span>
<span class="line">        <span class="token punctuation">}</span></span>
<span class="line"></span>
<span class="line">        <span class="token variable">$this</span><span class="token operator">-></span><span class="token property">value</span> <span class="token operator">=</span> <span class="token class-name static-context">Arr</span><span class="token operator">::</span><span class="token function">get</span><span class="token punctuation">(</span><span class="token variable">$inputs</span><span class="token punctuation">,</span> <span class="token variable">$this</span><span class="token operator">-></span><span class="token property">column</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line">        <span class="token variable">$value</span> <span class="token operator">=</span> <span class="token function">array_filter</span><span class="token punctuation">(</span><span class="token variable">$this</span><span class="token operator">-></span><span class="token property">value</span><span class="token punctuation">,</span> <span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token variable">$val</span><span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line">            <span class="token keyword">return</span> <span class="token variable">$val</span> <span class="token operator">!==</span> <span class="token string single-quoted-string">''</span><span class="token punctuation">;</span></span>
<span class="line">        <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line">        <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token keyword">empty</span><span class="token punctuation">(</span><span class="token variable">$value</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line">            <span class="token keyword">return</span><span class="token punctuation">;</span></span>
<span class="line">        <span class="token punctuation">}</span></span>
<span class="line"></span>
<span class="line">        <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token operator">!</span><span class="token keyword">isset</span><span class="token punctuation">(</span><span class="token variable">$value</span><span class="token punctuation">[</span><span class="token string single-quoted-string">'start'</span><span class="token punctuation">]</span><span class="token punctuation">)</span> <span class="token operator">&amp;&amp;</span> <span class="token keyword">isset</span><span class="token punctuation">(</span><span class="token variable">$value</span><span class="token punctuation">[</span><span class="token string single-quoted-string">'end'</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line">            <span class="token comment">// 这里返回的数组相当于</span></span>
<span class="line">            <span class="token comment">// $query->where($this->column, '&lt;=', $value['end']);</span></span>
<span class="line">            <span class="token keyword">return</span> <span class="token variable">$this</span><span class="token operator">-></span><span class="token function">buildCondition</span><span class="token punctuation">(</span><span class="token variable">$this</span><span class="token operator">-></span><span class="token property">column</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'&lt;='</span><span class="token punctuation">,</span> <span class="token variable">$value</span><span class="token punctuation">[</span><span class="token string single-quoted-string">'end'</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line">        <span class="token punctuation">}</span></span>
<span class="line"></span>
<span class="line">        <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token operator">!</span><span class="token keyword">isset</span><span class="token punctuation">(</span><span class="token variable">$value</span><span class="token punctuation">[</span><span class="token string single-quoted-string">'end'</span><span class="token punctuation">]</span><span class="token punctuation">)</span> <span class="token operator">&amp;&amp;</span> <span class="token keyword">isset</span><span class="token punctuation">(</span><span class="token variable">$value</span><span class="token punctuation">[</span><span class="token string single-quoted-string">'start'</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line">            <span class="token comment">// 这里返回的数组相当于</span></span>
<span class="line">            <span class="token comment">// $query->where($this->column, '>=', $value['end']);</span></span>
<span class="line">            <span class="token keyword">return</span> <span class="token variable">$this</span><span class="token operator">-></span><span class="token function">buildCondition</span><span class="token punctuation">(</span><span class="token variable">$this</span><span class="token operator">-></span><span class="token property">column</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'>='</span><span class="token punctuation">,</span> <span class="token variable">$value</span><span class="token punctuation">[</span><span class="token string single-quoted-string">'start'</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line">        <span class="token punctuation">}</span></span>
<span class="line"></span>
<span class="line">        <span class="token variable">$this</span><span class="token operator">-></span><span class="token property">query</span> <span class="token operator">=</span> <span class="token string single-quoted-string">'whereBetween'</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line">        <span class="token comment">// 这里返回的数组相当于</span></span>
<span class="line">        <span class="token comment">// $query->whereBetween($this->column, $value['end']);</span></span>
<span class="line">        <span class="token keyword">return</span> <span class="token variable">$this</span><span class="token operator">-></span><span class="token function">buildCondition</span><span class="token punctuation">(</span><span class="token variable">$this</span><span class="token operator">-></span><span class="token property">column</span><span class="token punctuation">,</span> <span class="token variable">$this</span><span class="token operator">-></span><span class="token property">value</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line">    <span class="token punctuation">}</span></span>
<span class="line"></span>
<span class="line">    <span class="token comment">// 自定义过滤器表单显示方式</span></span>
<span class="line">    <span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function-definition function">datetime</span><span class="token punctuation">(</span><span class="token variable">$options</span> <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">)</span></span>
<span class="line">    <span class="token punctuation">{</span></span>
<span class="line">        <span class="token variable">$this</span><span class="token operator">-></span><span class="token property">view</span> <span class="token operator">=</span> <span class="token string single-quoted-string">'admin::filter.betweenDatetime'</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line">        <span class="token class-name static-context">DateTime</span><span class="token operator">::</span><span class="token function">collectAssets</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line">        <span class="token variable">$this</span><span class="token operator">-></span><span class="token function">setupDatetime</span><span class="token punctuation">(</span><span class="token variable">$options</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line">        <span class="token keyword">return</span> <span class="token variable">$this</span><span class="token punctuation">;</span></span>
<span class="line">    <span class="token punctuation">}</span></span>
<span class="line"></span>
<span class="line">    <span class="token keyword">protected</span> <span class="token keyword">function</span> <span class="token function-definition function">setupDatetime</span><span class="token punctuation">(</span><span class="token variable">$options</span> <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">)</span></span>
<span class="line">    <span class="token punctuation">{</span></span>
<span class="line">        <span class="token variable">$options</span><span class="token punctuation">[</span><span class="token string single-quoted-string">'format'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token class-name static-context">Arr</span><span class="token operator">::</span><span class="token function">get</span><span class="token punctuation">(</span><span class="token variable">$options</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'format'</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'YYYY-MM-DD HH:mm:ss'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line">        <span class="token variable">$options</span><span class="token punctuation">[</span><span class="token string single-quoted-string">'locale'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token class-name static-context">Arr</span><span class="token operator">::</span><span class="token function">get</span><span class="token punctuation">(</span><span class="token variable">$options</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'locale'</span><span class="token punctuation">,</span> <span class="token function">config</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'app.locale'</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line">        <span class="token variable">$startOptions</span> <span class="token operator">=</span> <span class="token function">json_encode</span><span class="token punctuation">(</span><span class="token variable">$options</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line">        <span class="token variable">$endOptions</span> <span class="token operator">=</span> <span class="token function">json_encode</span><span class="token punctuation">(</span><span class="token variable">$options</span> <span class="token operator">+</span> <span class="token punctuation">[</span><span class="token string single-quoted-string">'useCurrent'</span> <span class="token operator">=></span> <span class="token constant boolean">false</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line">        <span class="token comment">// 通过上面格式化后的id对表单进行你想要的操作</span></span>
<span class="line">        <span class="token variable">$script</span> <span class="token operator">=</span> <span class="token string heredoc-string"><span class="token delimiter symbol"><span class="token punctuation">&lt;&lt;&lt;</span>JS</span></span>
<span class="line">            $('#<span class="token interpolation"><span class="token punctuation">{</span><span class="token variable">$this</span><span class="token operator">-></span><span class="token property">id</span><span class="token punctuation">[</span><span class="token string single-quoted-string">'start'</span><span class="token punctuation">]</span><span class="token punctuation">}</span></span>').datetimepicker(<span class="token interpolation"><span class="token variable">$startOptions</span></span>);</span>
<span class="line">            $('#<span class="token interpolation"><span class="token punctuation">{</span><span class="token variable">$this</span><span class="token operator">-></span><span class="token property">id</span><span class="token punctuation">[</span><span class="token string single-quoted-string">'end'</span><span class="token punctuation">]</span><span class="token punctuation">}</span></span>').datetimepicker(<span class="token interpolation"><span class="token variable">$endOptions</span></span>);</span>
<span class="line">            $("#<span class="token interpolation"><span class="token punctuation">{</span><span class="token variable">$this</span><span class="token operator">-></span><span class="token property">id</span><span class="token punctuation">[</span><span class="token string single-quoted-string">'start'</span><span class="token punctuation">]</span><span class="token punctuation">}</span></span>").on("dp.change", function (e) {</span>
<span class="line">                $('#<span class="token interpolation"><span class="token punctuation">{</span><span class="token variable">$this</span><span class="token operator">-></span><span class="token property">id</span><span class="token punctuation">[</span><span class="token string single-quoted-string">'end'</span><span class="token punctuation">]</span><span class="token punctuation">}</span></span>').data("DateTimePicker").minDate(e.date);</span>
<span class="line">            });</span>
<span class="line">            $("#<span class="token interpolation"><span class="token punctuation">{</span><span class="token variable">$this</span><span class="token operator">-></span><span class="token property">id</span><span class="token punctuation">[</span><span class="token string single-quoted-string">'end'</span><span class="token punctuation">]</span><span class="token punctuation">}</span></span>").on("dp.change", function (e) {</span>
<span class="line">                $('#<span class="token interpolation"><span class="token punctuation">{</span><span class="token variable">$this</span><span class="token operator">-></span><span class="token property">id</span><span class="token punctuation">[</span><span class="token string single-quoted-string">'start'</span><span class="token punctuation">]</span><span class="token punctuation">}</span></span>').data("DateTimePicker").maxDate(e.date);</span>
<span class="line">            });</span>
<span class="line"><span class="token delimiter symbol">JS<span class="token punctuation">;</span></span></span></span>
<span class="line"></span>
<span class="line">        <span class="token class-name static-context">Admin</span><span class="token operator">::</span><span class="token function">script</span><span class="token punctuation">(</span><span class="token variable">$script</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line">    <span class="token punctuation">}</span></span>
<span class="line"><span class="token punctuation">}</span></span>
<span class="line"></span></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p><code v-pre>admin::filter.between</code>模板内容如下：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token operator">&lt;</span>div <span class="token keyword">class</span><span class="token operator">=</span><span class="token string double-quoted-string">"filter-input col-sm-{{ <span class="token interpolation"><span class="token variable">$width</span></span> }} "</span>  style<span class="token operator">=</span><span class="token string double-quoted-string">"{!! <span class="token interpolation"><span class="token variable">$style</span></span> !!}"</span><span class="token operator">></span></span>
<span class="line">    <span class="token operator">&lt;</span>div <span class="token keyword">class</span><span class="token operator">=</span><span class="token string double-quoted-string">"form-group"</span> <span class="token operator">></span></span>
<span class="line">        <span class="token operator">&lt;</span>div <span class="token keyword">class</span><span class="token operator">=</span><span class="token string double-quoted-string">"input-group input-group-sm"</span><span class="token operator">></span></span>
<span class="line">            <span class="token operator">&lt;</span>span <span class="token keyword">class</span><span class="token operator">=</span><span class="token string double-quoted-string">"input-group-addon"</span><span class="token operator">></span><span class="token operator">&lt;</span>b<span class="token operator">></span><span class="token punctuation">{</span><span class="token operator">!</span><span class="token operator">!</span> <span class="token variable">$label</span> <span class="token operator">!</span><span class="token operator">!</span><span class="token punctuation">}</span><span class="token operator">&lt;</span><span class="token operator">/</span>b<span class="token operator">></span><span class="token operator">&lt;</span><span class="token operator">/</span>span<span class="token operator">></span></span>
<span class="line">            <span class="token operator">&lt;</span>input type<span class="token operator">=</span><span class="token string double-quoted-string">"text"</span> <span class="token keyword">class</span><span class="token operator">=</span><span class="token string double-quoted-string">"form-control"</span> placeholder<span class="token operator">=</span><span class="token string double-quoted-string">"{<span class="token interpolation"><span class="token punctuation">{</span><span class="token variable">$label</span><span class="token punctuation">}</span></span>}"</span> name<span class="token operator">=</span><span class="token string double-quoted-string">"{<span class="token interpolation"><span class="token punctuation">{</span><span class="token variable">$name</span><span class="token punctuation">[</span><span class="token string single-quoted-string">'start'</span><span class="token punctuation">]</span><span class="token punctuation">}</span></span>}"</span> value<span class="token operator">=</span><span class="token string double-quoted-string">"{{ request(<span class="token interpolation"><span class="token variable">$name</span><span class="token punctuation">[</span><span class="token string single-quoted-string">'start'</span><span class="token punctuation">]</span></span>, \Illuminate\Support\Arr::get(<span class="token interpolation"><span class="token variable">$value</span></span>, 'start')) }}"</span><span class="token operator">></span></span>
<span class="line">            <span class="token operator">&lt;</span>span <span class="token keyword">class</span><span class="token operator">=</span><span class="token string double-quoted-string">"input-group-addon"</span> style<span class="token operator">=</span><span class="token string double-quoted-string">"border-left: 0; border-right: 0;"</span><span class="token operator">></span>To<span class="token operator">&lt;</span><span class="token operator">/</span>span<span class="token operator">></span></span>
<span class="line">            <span class="token operator">&lt;</span>input type<span class="token operator">=</span><span class="token string double-quoted-string">"text"</span> <span class="token keyword">class</span><span class="token operator">=</span><span class="token string double-quoted-string">"form-control"</span> placeholder<span class="token operator">=</span><span class="token string double-quoted-string">"{<span class="token interpolation"><span class="token punctuation">{</span><span class="token variable">$label</span><span class="token punctuation">}</span></span>}"</span> name<span class="token operator">=</span><span class="token string double-quoted-string">"{<span class="token interpolation"><span class="token punctuation">{</span><span class="token variable">$name</span><span class="token punctuation">[</span><span class="token string single-quoted-string">'end'</span><span class="token punctuation">]</span><span class="token punctuation">}</span></span>}"</span> value<span class="token operator">=</span><span class="token string double-quoted-string">"{{ request(<span class="token interpolation"><span class="token variable">$name</span><span class="token punctuation">[</span><span class="token string single-quoted-string">'end'</span><span class="token punctuation">]</span></span>, \Illuminate\Support\Arr::get(<span class="token interpolation"><span class="token variable">$value</span></span>, 'end')) }}"</span><span class="token operator">></span></span>
<span class="line">        <span class="token operator">&lt;</span><span class="token operator">/</span>div<span class="token operator">></span></span>
<span class="line">    <span class="token operator">&lt;</span><span class="token operator">/</span>div<span class="token operator">></span></span>
<span class="line"><span class="token operator">&lt;</span><span class="token operator">/</span>div<span class="token operator">></span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p><code v-pre>admin::filter.betweenDatetime</code>模板内容如下：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token operator">&lt;</span>div <span class="token keyword">class</span><span class="token operator">=</span><span class="token string double-quoted-string">"filter-input col-sm-{{ <span class="token interpolation"><span class="token variable">$width</span></span> }}"</span>  style<span class="token operator">=</span><span class="token string double-quoted-string">"{!! <span class="token interpolation"><span class="token variable">$style</span></span> !!}"</span><span class="token operator">></span></span>
<span class="line">    <span class="token operator">&lt;</span>div <span class="token keyword">class</span><span class="token operator">=</span><span class="token string double-quoted-string">"form-group"</span><span class="token operator">></span></span>
<span class="line">        <span class="token operator">&lt;</span>div <span class="token keyword">class</span><span class="token operator">=</span><span class="token string double-quoted-string">"input-group input-group-sm"</span><span class="token operator">></span></span>
<span class="line">            <span class="token operator">&lt;</span>span <span class="token keyword">class</span><span class="token operator">=</span><span class="token string double-quoted-string">"input-group-addon"</span><span class="token operator">></span><span class="token operator">&lt;</span>b<span class="token operator">></span><span class="token punctuation">{</span><span class="token punctuation">{</span><span class="token variable">$label</span><span class="token punctuation">}</span><span class="token punctuation">}</span><span class="token operator">&lt;</span><span class="token operator">/</span>b<span class="token operator">></span>  <span class="token operator">&amp;</span>nbsp<span class="token punctuation">;</span><span class="token operator">&lt;</span>i <span class="token keyword">class</span><span class="token operator">=</span><span class="token string double-quoted-string">"fa fa-calendar"</span><span class="token operator">></span><span class="token operator">&lt;</span><span class="token operator">/</span>i<span class="token operator">></span><span class="token operator">&lt;</span><span class="token operator">/</span>span<span class="token operator">></span></span>
<span class="line">            <span class="token operator">&lt;</span>input type<span class="token operator">=</span><span class="token string double-quoted-string">"text"</span> <span class="token keyword">class</span><span class="token operator">=</span><span class="token string double-quoted-string">"form-control"</span> id<span class="token operator">=</span><span class="token string double-quoted-string">"{<span class="token interpolation"><span class="token punctuation">{</span><span class="token variable">$id</span><span class="token punctuation">[</span><span class="token string single-quoted-string">'start'</span><span class="token punctuation">]</span><span class="token punctuation">}</span></span>}"</span> placeholder<span class="token operator">=</span><span class="token string double-quoted-string">"{<span class="token interpolation"><span class="token punctuation">{</span><span class="token variable">$label</span><span class="token punctuation">}</span></span>}"</span> name<span class="token operator">=</span><span class="token string double-quoted-string">"{<span class="token interpolation"><span class="token punctuation">{</span><span class="token variable">$name</span><span class="token punctuation">[</span><span class="token string single-quoted-string">'start'</span><span class="token punctuation">]</span><span class="token punctuation">}</span></span>}"</span> value<span class="token operator">=</span><span class="token string double-quoted-string">"{{ request(<span class="token interpolation"><span class="token variable">$name</span><span class="token punctuation">[</span><span class="token string single-quoted-string">'start'</span><span class="token punctuation">]</span></span>, \Illuminate\Support\Arr::get(<span class="token interpolation"><span class="token variable">$value</span></span>, 'start')) }}"</span><span class="token operator">></span></span>
<span class="line">            <span class="token operator">&lt;</span>span <span class="token keyword">class</span><span class="token operator">=</span><span class="token string double-quoted-string">"input-group-addon"</span> style<span class="token operator">=</span><span class="token string double-quoted-string">"border-left: 0; border-right: 0;"</span><span class="token operator">></span>To<span class="token operator">&lt;</span><span class="token operator">/</span>span<span class="token operator">></span></span>
<span class="line">            <span class="token operator">&lt;</span>input type<span class="token operator">=</span><span class="token string double-quoted-string">"text"</span> <span class="token keyword">class</span><span class="token operator">=</span><span class="token string double-quoted-string">"form-control"</span> id<span class="token operator">=</span><span class="token string double-quoted-string">"{<span class="token interpolation"><span class="token punctuation">{</span><span class="token variable">$id</span><span class="token punctuation">[</span><span class="token string single-quoted-string">'end'</span><span class="token punctuation">]</span><span class="token punctuation">}</span></span>}"</span> placeholder<span class="token operator">=</span><span class="token string double-quoted-string">"{<span class="token interpolation"><span class="token punctuation">{</span><span class="token variable">$label</span><span class="token punctuation">}</span></span>}"</span> name<span class="token operator">=</span><span class="token string double-quoted-string">"{<span class="token interpolation"><span class="token punctuation">{</span><span class="token variable">$name</span><span class="token punctuation">[</span><span class="token string single-quoted-string">'end'</span><span class="token punctuation">]</span><span class="token punctuation">}</span></span>}"</span> value<span class="token operator">=</span><span class="token string double-quoted-string">"{{ request(<span class="token interpolation"><span class="token variable">$name</span><span class="token punctuation">[</span><span class="token string single-quoted-string">'end'</span><span class="token punctuation">]</span></span>, \Illuminate\Support\Arr::get(<span class="token interpolation"><span class="token variable">$value</span></span>, 'end')) }}"</span><span class="token operator">></span></span>
<span class="line">        <span class="token operator">&lt;</span><span class="token operator">/</span>div<span class="token operator">></span></span>
<span class="line">    <span class="token operator">&lt;</span><span class="token operator">/</span>div<span class="token operator">></span></span>
<span class="line"><span class="token operator">&lt;</span><span class="token operator">/</span>div<span class="token operator">></span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>现在只要调用<code v-pre>extend</code>方法可以使用了，打开<code v-pre>app/Admin/bootstrap.php</code>，加入以下代码：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token class-name static-context">Filter</span><span class="token operator">::</span><span class="token function">extend</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'customBetween'</span><span class="token punctuation">,</span> <span class="token class-name class-name-fully-qualified static-context">Filter<span class="token punctuation">\</span>Between</span><span class="token operator">::</span><span class="token keyword">class</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><p>使用：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token variable">$filter</span><span class="token operator">-></span><span class="token function">customBetween</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'created_at'</span><span class="token punctuation">)</span><span class="token operator">-></span><span class="token function">datetime</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div></div></template>


